package com.example.myanimationproperty;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f);
        valueAnimator.setDuration(2000);
        valueAnimator.addUpdateListener(a -> {
            float value = (float) a.getAnimatedValue();
            Log.i(TAG, "onAnimatorUpdate: " + value);
        });
        valueAnimator.start();

        // ObjectAnimator
        TextView tvHello = findViewById(R.id.tv_hello);
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(tvHello, "alpha", 0f, 1f);
        objectAnimator.setDuration(3000);
        objectAnimator.start();

        // 监听器
        objectAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(@NonNull Animator animation) {
                // 动画开始时调用

            }

            @Override
            public void onAnimationEnd(@NonNull Animator animation) {
                // 动画结束时调用

            }

            @Override
            public void onAnimationCancel(@NonNull Animator animation) {
                // 动画被取消的时候调用

            }

            @Override
            public void onAnimationRepeat(@NonNull Animator animation) {
                // 动画重复执行的时候调用

            }
        });

        // 使用监听器适配器选择某个需要监听的方法执行
        objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
            }
        });

    }
}